package com.itheima.algorithm.binarysearch;


import org.springframework.util.StopWatch;

/**
 * @author: TylerZhong
 * @description:
 */
public class TestCacheLine {
    public static void ij(int[][] a, int rows, int colums) {
        long sum = 0L;
        for (int i = 0; i < rows; i++) {
            for (int j = 0; j < colums; j++) {
                sum += a[i][j];
            }
        }
    }

    public static void ji(int[][] a, int rows, int colums) {
        long sum = 0L;
        for (int j = 0; j < colums; j++) {
            for (int i = 0; i < rows; i++) {
                sum += a[i][j];
            }
        }
        System.out.println(sum);
    }

    public static void main(String[] args){
        int rows = 1_000_000;
        int colums = 14;
        int[][] a = new int[rows][colums];

        StopWatch stopWatch = new StopWatch();
        stopWatch.start("ij");
        ij(a, rows, colums);
        stopWatch.stop();

        stopWatch.start("ji");
        ji(a, rows, colums);
        stopWatch.stop();

        System.out.println(stopWatch.prettyPrint());

    }

}
